//
//  IndividualScreen.m
//  ZooNgonDoiOS
//
//  Created by Trung sound on 7/24/12.
//  Copyright (c) 2012 Personal. All rights reserved.
//

#import "IndividualScreen.h"
#import "GetMeTask.h"

@implementation IndividualScreen
#define VIEW_HEADER_HEIGHT 48
#define ITEM_HEADER_WIDTH 80
#define VIEW_TABBAR_HEIGHT 42
#define ANIMATION_DURATION 0.5

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        _vTabbar = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 42)];
        _btnFeed = [[UIButton alloc]init];
        _btnFriend = [[UIButton alloc]init];
        _btnProfile = [[UIButton alloc]init];
        _lbFeed = [[UILabel alloc]init];
        _lbFriend = [[UILabel alloc]init];
        _lbProfile = [[UILabel alloc]init];   
        _vUnderTabbar = [[UIView alloc]init];
        [_vUnderTabbar setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:IMG_VIEW_TABBAR]]];
        
        _profileScreenTableView = [[ProfileScreenTableView alloc]initWithFrame:CGRectMake(0, 42, self.bounds.size.width, self.bounds.size.height -42)];
        view_1_ = [[UIView alloc] initWithFrame:CGRectMake(0, 0, page_width, page_height)];
        view_2_ = [[UIView alloc] initWithFrame:CGRectMake(page_width, 0, page_width, page_height)];
        view_3_ = [[UIView alloc] initWithFrame:CGRectMake( 2 * page_width, 0, page_width, page_height)];
        
        _baseScroll = [[UIScrollView alloc]init];
        _baseScroll.delegate = self;
        _baseScroll.pagingEnabled = YES;
        _baseScroll.showsHorizontalScrollIndicator = NO;
        
        _baseScroll.contentSize = CGSizeMake(page_width * 3, page_height);
        [_baseScroll setContentOffset:CGPointMake(page_width, 0)];
        
        [_baseScroll addSubview:view_1_];
        [_baseScroll addSubview:view_2_];
        [_baseScroll addSubview:view_3_];
        
        currentPageNumber_ = 1;
        [self setupView];
    }
    return self;
}

-(void) setupView {
        // Draw view Tabbar
    _vTabbar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:TABBAR_BACKGROUND]];
    _btnFeed.frame = CGRectMake(0, 0, self.bounds.size.width /3, VIEW_TABBAR_HEIGHT);
    [_btnFeed setBackgroundColor:[UIColor clearColor]];
    [_btnFeed addTarget:self action:@selector(btnFeedClicked) forControlEvents:UIControlEventTouchUpInside];
    
    _lbFeed.frame = CGRectMake(20, 5, 65, 30);
    _lbFeed.backgroundColor = [UIColor clearColor];
    [_lbFeed setText:STRING_FEED];
    [_lbFeed setFont:[UIFont fontWithName:APP_MAIN_FONT size:15]];
    [_lbFeed setTextColor:[UIColor grayColor]];
    [_btnFeed addSubview:_lbFeed];
    
    _btnFriend.frame = CGRectMake((self.bounds.size.width /3), 0, self.bounds.size.width /3, VIEW_TABBAR_HEIGHT);
    [_btnFriend setBackgroundColor:[UIColor clearColor]];
    [_btnFriend addTarget:self action:@selector(btnFriendClicked) forControlEvents:UIControlEventTouchUpInside];
    
    _lbFriend.frame = CGRectMake(15, 5, 70, 30);
    _lbFriend.backgroundColor = [UIColor clearColor];
    [_lbFriend setText:STRING_FRIEND];
    [_lbFriend setFont:[UIFont fontWithName:APP_MAIN_FONT size:15]];
    [_lbFriend setTextColor:[UIColor whiteColor]];
    [_btnFriend addSubview:_lbFriend];
    
    _btnProfile.frame = CGRectMake((self.bounds.size.width /3)*2, 0, self.bounds.size.width /3, VIEW_TABBAR_HEIGHT);
    [_btnProfile setBackgroundColor:[UIColor clearColor]];
    [_btnProfile addTarget:self action:@selector(btnProfileClicked) forControlEvents:    UIControlEventTouchUpInside];
    
    _lbProfile.frame = CGRectMake(20, 5, 65, 30);
    _lbProfile.backgroundColor = [UIColor clearColor];
    [_lbProfile setText:STRING_PROFILE];
    [_lbProfile setFont:[UIFont fontWithName:APP_MAIN_FONT size:15]];
    [_lbProfile setTextColor:[UIColor grayColor]];
    [_btnProfile addSubview:_lbProfile];
    
    _vUnderTabbar.frame = CGRectMake(self.bounds.size.width/3, VIEW_TABBAR_HEIGHT - 5, self.bounds.size.width/3, 5);
    
    [_vTabbar addSubview:_vUnderTabbar];
    [_vTabbar addSubview:_btnFeed];
    [_vTabbar addSubview:_btnFriend];
    [_vTabbar addSubview:_btnProfile];
    
//    UIView *vHeader = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 160)];
//    [vHeader setBackgroundColor:[UIColor whiteColor]];
//    [_profileScreenTableView addSubview:vHeader];
    
    [self addSubview:_vTabbar];
    [self addSubview:_profileScreenTableView];
}

-(void)btnFeedClicked {
    [UIView animateWithDuration:ANIMATION_DURATION animations:^{
        _vUnderTabbar.frame = CGRectMake(0, VIEW_TABBAR_HEIGHT - 5, self.bounds.size.width/3, 5);
        [_lbFeed setTextColor:[UIColor whiteColor]];
        [_lbFriend setTextColor:[UIColor grayColor]];
        [_lbProfile setTextColor:[UIColor grayColor]];    
        [_vTabbar addSubview:_vUnderTabbar];
    }completion:nil];
    
}

-(void)btnFriendClicked {
    [UIView animateWithDuration:ANIMATION_DURATION animations:^{
        _vUnderTabbar.frame = CGRectMake(self.bounds.size.width/3, VIEW_TABBAR_HEIGHT - 5, self.bounds.size.width/3, 5);
        [_lbFeed setTextColor:[UIColor grayColor]];
        [_lbFriend setTextColor:[UIColor whiteColor]];
        [_lbProfile setTextColor:[UIColor grayColor]];    
        [_vTabbar addSubview:_vUnderTabbar];
    }completion:nil];
}

-(void)btnProfileClicked {
    [UIView animateWithDuration:ANIMATION_DURATION animations:^{
        _vUnderTabbar.frame = CGRectMake((self.bounds.size.width/3)*2, VIEW_TABBAR_HEIGHT - 5, self.bounds.size.width/3, 5);
        [_lbFeed setTextColor:[UIColor grayColor]];
        [_lbFriend setTextColor:[UIColor grayColor]];
        [_lbProfile setTextColor:[UIColor whiteColor]];    
        [_vTabbar addSubview:_vUnderTabbar];
    }completion:nil];
    
    GetMeTask *getMeTask = [[GetMeTask alloc]init];
    [getMeTask doExecute];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
